<template>
    <div>
        欢迎：{{username}}
        <br>
        <br>
        <van-field v-model="form.title" label='标题' />
        <van-field  v-model="form.content" type='textarea' placrholder='请输入内容' cols=6 />
        <van-button color="linear-gradient(to right, #ff6034,#7232dd)" @click="add">
            添加
        </van-button>
        <br>
        <br>
        展示文章<br>
        <van-button color="linear-gradient(to right, #7232dd, #ee0a24)" @click="my">
            我的文章
        </van-button>
        <table>
            <tr>
                <td>id</td>
                <td>标题</td>
                <td>内容</td>
            </tr>
            <tr v-for="i in list">
                <td>{{i.id}}</td>
                <td>{{i.title}}</td>
                <td>{{i.content}}</td>
            </tr>
        </table>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                username:localStorage.getItem('username'),
                userid:localStorage.getItem('userid'),
                form:{userid:localStorage.getItem('userid')},
                list:[],
                uid:0
            }
        },
        methods:{
            add(){
                this.$axios.post('auser/articleM',this.form).then(res=>{
                    alert('添加成功')
                    this.get_list()
                })
            },
            get_list(){
                this.$axios.get('auser/articleM?uid='+this.uid).then(res=>{
                    this.list = res.data.list
                })
            },
            my(){
                this.uid = localStorage.getItem('userid')
                this.get_list()
            }
        },
        mounted(){
            this.get_list()
        }
    }
</script>

<style scoped>

</style>